package com.veer.shop.service.impl.admin;

import java.util.concurrent.TimeUnit;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import com.veer.shop.config.Constants;
import com.veer.shop.pojo.PhoneVcode;
import com.veer.shop.pojo.ResponseData;
import com.veer.shop.service.admin.PhoneSerive;
import com.veer.shop.utils.RedisUtil;
import com.veer.shop.utils.ResponseUtil;
/**
 * 手机相关业务实现类
 * 
 * @author WangBin
 * 2021年1月4日-下午3:22:17
 */
@Service
public class PhoneServiceImpl implements PhoneSerive {

	@Autowired
	private RedisUtil redisUtil;
	
	/**
	 * 获取手机验证码
	 */
	@Override
	public ResponseData<?> getVCode(String phone) {
		
		if(StringUtils.isEmpty(phone))return ResponseUtil.error("请填写手机号");
		
		// 获取手机验证码
		String vcode = "808080";
		// 存入缓存
		redisUtil.set(Constants.REDIS_SUFFIX_PHONE_VCODE + phone, vcode);
		redisUtil.expire(Constants.REDIS_SUFFIX_PHONE_VCODE + phone, Constants.REDIS_PHONE_VCODE_LIFE_TIME, TimeUnit.SECONDS);
		PhoneVcode phoneVcode = new PhoneVcode();
		phoneVcode.setVcode(vcode);
		return ResponseUtil.success(phoneVcode);
	}
}
